﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_user_AddNewUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            foreach (var item in EnumUtility.EnumToList<UserManagement.Role>())
            {
                ddlRole.Items.Add(EnumUtility.GetEnumNiceName(item));
            }
        }
    }

    protected void btnCreatUser_Click(object sender, EventArgs e)
    {
        if (!UserManagement.UserExists(txtUserName.Text.Trim()))
        {
            UserManagement userManagement = new UserManagement();
            if (userManagement.CreateUser(txtUserName.Text, txtPassword.Text, txtFullName.Text, txtEmail.Text, ddlRole.SelectedIndex, txtOrganization.Text))
                LiteralMessage.Text = "New User created successfully!";
            else
                LiteralMessage.Text = "Cannot create user, probably database problem!";
        }
        else
        {
            LiteralMessage.Text = "This username is already used, please choose another name!";
        }
    }
}